package com.codebattery.service;


import com.codebattery.domain.entity.GoodsAttr;
import com.codebattery.domain.entity.GoodsAttrValue;
import com.codebattery.mapper.BaseMapper;
import com.codebattery.repository.GoodsAttrMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsAttrService extends  MyBatisBaseServiceImpl<GoodsAttr, Integer>{
    private static final Logger logger = LoggerFactory.getLogger(GoodsAttrService.class);

    @Resource
    private GoodsAttrMapper goodsAttrMapper;
    @Resource
    private GoodsAttrValueService goodsAttrValueService;

    @Override
    protected BaseMapper<GoodsAttr, Integer> mapper() {
        return goodsAttrMapper;
    }

    public List<GoodsAttr> selectGoodsAttr(Integer goodsId){
        return goodsAttrMapper.selectByGoodsId(goodsId);
    }

    public void addGoodsAttr(GoodsAttr goodsAttr) {
        if(goodsAttr.getValues()!=null){
            for(GoodsAttrValue attrValue : goodsAttr.getValues()){
                goodsAttrValueService.insert(attrValue);
            }
        }
    }
}
